/*
 * ActivityRenderer.java
 *
 * Created on 31 de Maio de 2007, 20:57
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.jerm.Interface.JGraph_Diagrama;

import java.awt.BasicStroke;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Polygon;

import org.jgraph.graph.GraphConstants;
import org.jgraph.graph.VertexRenderer;

/**
 *
 * @author Tiago Falcao
 */
public class JGraphRetLosangoRenderer extends VertexRenderer {

		/**
		 * Return a slightly larger preferred size than for a rectangle.
		 */
		public Dimension getPreferredSize() {
			Dimension d = super.getPreferredSize();
			d.width += d.height / 5;
			return d;
		}

		public void paint(Graphics g) {
			int b = borderWidth;
			Graphics2D g2 = (Graphics2D) g;
			Dimension d = getSize();
			boolean tmp = selected;
                        int x[]={b/2,b/2+d.width/2, d.width - (int)(b*1.5),d.width/2 - (int)(b*1.5)};
                        int y[]={b/2+d.height/2,b/2,d.height/2 - (int)(b*1.5),d.height - (int)(b*1.5)};
                        Polygon Polygon=new Polygon(x,y,4);
			if (super.isOpaque()) {
				g.setColor(super.getBackground());
				if (gradientColor != null && !preview) {
					setOpaque(false);
					g2.setPaint(new GradientPaint(0, 0, getBackground(),
							getWidth(), getHeight(), gradientColor, true));
				}
                                g.fillRect(b / 2, b / 2, d.width - (int) (b * 1.5),d.height - (int) (b * 1.5));
                                g.fillPolygon (Polygon);
                        }
			try {
				setBorder(null);
				setOpaque(false);
				selected = false;
				super.paint(g);
			} finally {
				selected = tmp;
			}
			if (bordercolor != null) {
				g.setColor(bordercolor);
				g2.setStroke(new BasicStroke(b));
                                g.drawPolygon (Polygon);
				g.drawRect(b / 2, b / 2, d.width - (int) (b * 1.5),
						d.height - (int) (b * 1.5));
			}
			if (selected) {
				g2.setStroke(GraphConstants.SELECTION_STROKE);
				g.setColor(highlightColor);
                                g.drawPolygon (Polygon);
				g.drawRect(b / 2, b / 2, d.width - (int) (b * 1.5),
						d.height - (int) (b * 1.5));
			}
                        
		}
                
        
	}
